package com.hkts.naturalgas.performance.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.performance.entity.HkActType;
import com.hkts.naturalgas.performance.mapper.HkActTypeMapper;
import com.hkts.naturalgas.performance.service.IHkActTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yck
 * @since 2022-09-02
 */
@Service
@Transactional
public class HkActTypeServiceImpl extends ServiceImpl<HkActTypeMapper, HkActType> implements IHkActTypeService {


    @Autowired
    private HkActTypeMapper hkActTypeMapper;

    @Override
    public IPage<HkActType> selectPage(Page<HkActType> page, HkActType hkActType) {
        QueryWrapper<HkActType> query = Wrappers.query();
        QueryWrapper<HkActType> entityWrapper = getEntityWrapper(query, hkActType);
        return hkActTypeMapper.selectPage(page, entityWrapper);
    }


    @Override
    public List<HkActType> selectList(HkActType hkActType) {
        QueryWrapper<HkActType> query = Wrappers.query();
        QueryWrapper<HkActType> entityWrapper = getEntityWrapper(query, hkActType);
        return hkActTypeMapper.selectList(entityWrapper);
    }

    /**
     * 公共查询条件
     *
     * @param entityWrapper
     * @return
     */
    public QueryWrapper<HkActType> getEntityWrapper(QueryWrapper<HkActType> entityWrapper, HkActType hkActType) {
        //条件拼接
        if (StringUtils.isNotBlank(hkActType.getActTypeName())) {
            entityWrapper.like(HkActType.ACT_TYPE_NAME, hkActType.getActTypeName());
        }
        if (StringUtils.isNotBlank(hkActType.getCreateBy())) {
            entityWrapper.like(HkActType.CREATE_BY, hkActType.getCreateBy());
        }
        return entityWrapper;
    }
}
